package tx.bj12320.process;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.impl.ProcessEngineImpl;
import org.activiti.engine.impl.db.DbSqlSession;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.interceptor.CommandExecutor;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;

public class ProcessManagement {
	private static Logger log = Logger.getLogger(ProcessManagement.class.getName());
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		// Create Activiti process engine

		  ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

		  // Get Activiti services
		  RepositoryService repositoryService = processEngine.getRepositoryService();
		  RuntimeService runtimeService = processEngine.getRuntimeService();
		  TaskService taskService = processEngine.getTaskService();
		  // Deploy the process definition
		  repositoryService.createDeployment()
		    .addClasspathResource("tx/bj12320/process/tousu_zhuanban.bpmn20.xml")
		    .deploy();



	}

	public static void clean(){
		ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
		CommandExecutor commandExecutor = ((ProcessEngineImpl)processEngine).getProcessEngineConfiguration().getCommandExecutorTxRequired();
	      commandExecutor.execute(new Command<Object>() {
	        public Object execute(CommandContext commandContext) {
	          DbSqlSession session = commandContext.getSession(DbSqlSession.class);
	          session.dbSchemaDrop();
	          session.dbSchemaCreate();
	          return null;
	        }
	      });
	}

}
